package org.yoyo.classroom.service.impl;

import com.baomidou.mybatisplus.plugins.pagination.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yoyo.classroom.domain.po.Notice;
import org.yoyo.classroom.domain.query.NoticeQuery;
import org.yoyo.classroom.mapper.NoticeMapper;
import org.yoyo.classroom.service.NoticeService;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2024/12/22/10:42
 **/
@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public PageInfo<Notice> getNoticeList(NoticeQuery query) {
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<Notice> list = noticeMapper.selectNoticeList(query);
        return new PageInfo<>(list);
    }

    @Override
    public int addNotice(Notice notice) {
        notice.setType(1); // 默认为公告类型
        notice.setStatus("0"); // 默认未发布
        return noticeMapper.insert(notice);
    }

    @Override
    public int updateNotice(Notice notice) {

        return noticeMapper.update(notice);
    }

    @Override
    public int deleteNotice(Long id) {
        return noticeMapper.delete(id);
    }

    @Override
    public int updateStatus(Long id, String status) {
        return noticeMapper.updateStatus(id, status);
    }
}